<?php

class MLecturers extends CI_Model{

	public function __construct()
    {
        parent::__construct();
    }
	
	function getThesis($id){
	    $data = array();
	    $this->db->where('thesis_id',id_clean($id));
	    $this->db->limit(1);
	    $Q = $this->db->get('thesis');
	    if ($Q->num_rows() > 0){
	      $data = $Q->row_array();
	    }
	
	    $Q->free_result();    
	    return $data;    
	 }
	 
	function getLecturerName($username){
	    $data = array();
	    $this->db->select('user.uid,user.username,user.role_id,user.activate');
	    $this->db->from('user');
	    $this->db->join('lecturer', 'lecturer.uid=user.uid');
	    $this->db->where('user.activate',1);
	    $this->db->where('user.username',db_clean($username));
	    $this->db->limit(1);
	    $Q = $this->db->get();
	    if ($Q->num_rows() > 0){
	      $data = $Q->row_array();
	    }
	
	    $Q->free_result();    
	    return $data;    
	}
	
	function getCourses($userid){
		$data = array();
	    $this->db->where('uid',id_clean($userid));
	    $this->db->order_by("title", "ASC");
	    $Q = $this->db->get('course');
	    if ($Q->num_rows() > 0){
	    	foreach ($Q->result_array() as $row){
	        	 $data[] = $row;
	      	 }
	    }
	    $Q->free_result();  
	    return $data;   
	}
	 
	function getAllResources($userid){
	     $data = array();
	     $this->db->select('file.*,file_type.type as file_type, shift.title as shift, course.title as course');
	     $this->db->from('file');
	     $this->db->join('file_type','file.file_type_id = file_type.file_type_id');
	     $this->db->join('shift', 'file.shift_id = shift.shift_id');
	     $this->db->join('course','file.course_id = course.course_id');
	     $this->db->order_by("file.date_created", "desc");
	     $Q = $this->db->get();
	     if ($Q->num_rows() > 0){
	       foreach ($Q->result_array() as $row){
	         $data[] = $row;
	       }
	    }
	    $Q->free_result();  
	    return $data; 
	}
	
	function getResourceByCourse($courseid, $uid){
	     $data = array();
	     $this->db->select('file.*,file_type.type as file_type, shift.title as shift');
	     $this->db->from('file');
	     $this->db->join('file_type','file.file_type_id = file_type.file_type_id');
	     $this->db->join('shift', 'file.shift_id = shift.shift_id');
	     $this->db->where('file.course_id',id_clean($courseid));
	     $this->db->where('file.uid',id_clean($uid));
	     $this->db->order_by("file_type.type", "ASC");
	     $Q = $this->db->get();
	     if ($Q->num_rows() > 0){
	       foreach ($Q->result_array() as $row){
	         $data[] = $row;
	       }
	    }
	    $Q->free_result();  
	    return $data; 
	}
	
	function getAllLecturers()
	{
		$data = array();
		$data = array();
	    $this->db->select('user.uid,user.username,user.role_id,user.activate, lecturer.firstname, lecturer.lastname');
	    $this->db->from('user');
	    $this->db->join('lecturer', 'lecturer.uid=user.uid');
	    $this->db->where('role_id',3);
	    $this->db->order_by("firstname", "ASC");
	    $Q = $this->db->get();
	    if ($Q->num_rows() > 0){
	    	foreach ($Q->result_array() as $row){
	        	 $data[] = $row;
	      	 }
	    }
	    $Q->free_result();  
	    return $data;   
	}
	
	function getAllCourses()
	{
		$data = array();
	    $this->db->order_by("title", "ASC");
	    $Q = $this->db->get('course');
	    if ($Q->num_rows() > 0){
	    	foreach ($Q->result_array() as $row){
	        	 $data[] = $row;
	      	 }
	    }
	    $Q->free_result();  
	    return $data;   
	}
}

?>